package com.smart.campus.controller;

import com.smart.campus.dto.ShClass;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.ShClassServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.controller
 * @Author: JinBao shan
 * @date 2024/9/23 20:50
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "班级管理模块")
@Slf4j
@RestController
@RequestMapping(value = "class")
public class ShClassController {
    @Autowired
    private ShClassServiceFeign classServiceFeign;

    @ApiOperation(value = "班级列表分页查询",httpMethod = "POST",notes = "班级列表分页查询")
    @RequestMapping(value = "findShClassPagination")
    public ResponseResult<PagedResponse<ShClass>> findShClassPagination(@RequestBody ShClass shClass, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        return new ResponseResult<>(200,"班级列表分页查询成功",classServiceFeign.findShClassPagination(shClass,pageNum,pageSize));
    }

    @ApiOperation(value = "根据年级获取班级列表",httpMethod = "POST",notes = "根据年级获取班级列表")
    @RequestMapping(value = "getShClassList")
    public ResponseResult<List<ShClass>> getShClassList(@RequestParam(value = "grade") Integer grade){
        return new ResponseResult<>(200,"根据年级获取班级信息成功",classServiceFeign.getShClassList(grade));
    }

    @ApiOperation(value = "班级信息新增",httpMethod = "POST",notes = "班级信息新增")
    @RequestMapping(value = "addShClass")
    public ResponseResult addShClass(@RequestBody ShClass shClass){
        try {
            classServiceFeign.addShClass(shClass);
            return new ResponseResult<>(200,"班级信息新增成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班级信息新增失败");
        }
    }

    @ApiOperation(value = "根据班级id获取班级信息",httpMethod = "POST",notes = "根据班级id获取班级信息")
    @RequestMapping(value = "getShClassById")
    public ResponseResult<ShClass> getShClassById(@RequestParam(value = "id") Integer id){
        return new ResponseResult<>(200,"根据班级id获取班级信息成功",classServiceFeign.getShClassById(id));
    }

    @ApiOperation(value = "班级信息修改",httpMethod = "POST",notes = "班级信息修改")
    @RequestMapping(value = "updateShClassById")
    public ResponseResult updateShClassById(@RequestBody ShClass shClass){
        try {
            classServiceFeign.updateShClassById(shClass);
            return new ResponseResult<>(200,"班级信息修改成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班级信息修改失败");
        }
    }

    @ApiOperation(value = "班级信息删除",httpMethod = "POST",notes = "班级信息删除")
    @RequestMapping(value = "deleteShClassById")
    public ResponseResult deleteShClassById(@RequestParam(value = "id") Integer id){
        try {
            classServiceFeign.deleteShClassById(id);
            return new ResponseResult<>(200,"班级信息删除成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"班级信息删除失败");
        }
    }

    @RequestMapping(value = "getShClassListAll")
    public ResponseResult<List<ShClass>> getShClassListAll(){
        return new ResponseResult<>(200,"班级列表信息获取成功",classServiceFeign.getShClassListAll());
    }
}
